﻿@{
    ViewBag.Title = ViewBag.CurrentMenuName;
    Layout = "~/Views/Shared/_AdminLayout.cshtml";
}
<div class="content">
    <div class="clear"></div>
    <table style="width: 100%">
        <tr>
            <td style="height: 40px;">
                <div id="nav"><a href="/Role/Index" title="">@ViewBag.Title.ToUpper()</a></div>
            </td>
        </tr>
        <tr>
            <td style="">
                <div style="width: 90%;">
                    <div>
                        <div class="col-md-2" style="text-align: right; padding: 4px; ">                            
                            <label>Tên vai trò</label>
                        </div>
                        <div class="col-md-4">
                            <input type="text" class="txtsearch TextBoxContent" style="width: 100% !important" id="input-name" name="name">
                        </div>
                        <div class="col-md-2" style="text-align: right; padding: 4px;">
                            <label>Mã vai trò</label>                            
                        </div>
                        <div class="col-md-4">
                            <input type="text" class="txtsearch TextBoxContent" style="width: 100% !important" id="input-code" name="code">
                        </div>
                    </div>
                    <div>
                        <div class="col-md-2" style="text-align: right; padding: 4px;">
                            <label>Tên ứng dụng</label>
                        </div>
                        <div class="col-md-4">
                            @Html.DropDownList("appid", new SelectList(ViewBag.lstApp, "value", "text", 0), new { @id = "input-appid", @name = "appid", @class = "SelectBoxContent", @placeholder = "" })
                        </div>
                    </div>
                    <div>
                        <div style="height: 10px;"></div>
                        <div class="col-md-12">
                            <div style="padding-top: 10px; text-align: center">
                                <div class="col-md-12">
                                    <span class="input-group-btn">
                                        <button class="btn btn-primary" type="button" onclick="return btnSearchClick();">
                                            <span class="glyphicon glyphicon-search"></span>Tìm kiếm
                                        </button>

                                        <button type="button" id="role_add" style="margin-left: 10px;" class="btn btn-primary" value="Thêm mới"><span class="glyphicon glyphicon-plus"></span>Thêm vai trò</button>                           
                                    </span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <div id="role-list" style="margin-top:10px;">
                    @{
                        Html.RenderPartial("_RoleList");
                    }
                </div>
            </td>
        </tr>
    </table>
</div>
<script type="text/javascript">

    @functions{
        public string GetAntiForgeryToken()
        {
            string cookieToken, formToken;
            AntiForgery.GetTokens(null, out cookieToken, out formToken);
            return cookieToken + "," + formToken;
        }
    }

    function btnSearchClick() {
        OnCriteria(0);
    }

    $(document).ready(function () {
        $('#input-appid').change(function () {
            OnCriteria(0);
        });
    });

    $('#role_add').bind('click', function (event) {
        functionCreateOrUpdate(-1, "Thêm mới vai trò")
    });

    function functionCreateOrUpdate(roleID, titleForm) {
        $('#role-model-container')
         .load("/Role/actionPrepareCreateOrUpdateRole", { id: roleID }, function () {
             $(this).dialog({
                 draggable: true,
                 modal: true,
                 resizable: false,
                 width: 'auto',
                 title: titleForm,
                 minHeight: 75,
                 my: "center",
                 at: "center",
                 of: window,
                 buttons: [
                       {
                           text: "Lưu",
                           icons: {
                               primary: "ui-icon-heart"
                           },
                           class: 'btn btn-primary',
                           click: function () {
                               if ($('#idName').val() == "" || $('#IDrole').val() == "") {
                                   if (save) {
                                       var result = save();
                                       if (result) $(this).dialog("destroy");
                                   }
                               }
                               else
                               {
                                 var cName = checkName()
                                 var cCode = checkCode();
                                 if (cName == false || cCode == false)
                                     return;
                                 else {
                                     if (save) {
                                         var result = save();
                                         if (result) $(this).dialog("destroy");
                                     }
                                 }
                               }
                           }
                       },
                       {
                           text: "Đóng",
                           icons: {
                               primary: "ui-icon-close"
                           },
                           class: 'btn btn-primary',
                           click: function () {
                               $(this).dialog("destroy");
                           }

                       }
                 ]
             });
         });
    }
 
</script>